/*
package com.itheima.reggie.common.aop;

import com.itheima.reggie.common.MyTheadLocal;
import com.itheima.reggie.entity.MyParent;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.time.LocalDateTime;

@Component
@Aspect
public class MyAdvice {


    @Pointcut("execution(* com.itheima.reggie.controller.*Controller.add*(..))"
            + "||" +
            "execution(* com.itheima.reggie.controller.*Controller.update*(..))")
    private void pt() {
    }


    @Around("pt()")
    public Object advice(ProceedingJoinPoint pro) throws Throwable {
        Object proceed = null;

        Long id = MyTheadLocal.get();
        System.out.println("我是=============" + id);
        Object[] args = pro.getArgs();
        MyParent obj = (MyParent) args[0];
        String name = pro.getSignature().getName();
        if (name.startsWith("add")) {
            obj.setCreateTime(LocalDateTime.now());
            obj.setCreateUser(id);
        }
        obj.setUpdateTime(LocalDateTime.now());
        obj.setUpdateUser(id);
        proceed = pro.proceed(args);

        return proceed;
    }


}*/
